#include <bits/stdc++.h>
using namespace std;

const int N = 8;
int b[20];


int lowbit(int x)
{
	return x & (-x);
}

//修改某个值的函数
void add(int p, int x)
{
	for (int i = p; i <= N; i += lowbit(i))
	{
		b[i] += x;
	}
}

int count(int p)
{
	int result = 0;
	for (int i = p; i >= 1; i -= lowbit(i))
	{
		result += b[i];
	}
	return result;
}

int main()
{
	//修改该某个元素
	//建立数状数组
	for (int i = 1; i <= N; i++)
	{
		add(i, i);
		cout << b[i] << " ";
	}
	
//	cout << endl;
//	//求前n个数的和
//	for (int i = 1; i <= N; i++)
//		cout << count(i) << " ";
//	cout << endl;
//	
//	//前缀和思想区间和
//	cout << count(3) - count(2) << endl;
	
	cout << endl;
	//在某个区间上加上一个数
	for (int i = 3; i <= 5; i++)
		add(i, 1);
		
	for (int i = 6; i <= N; i++)
		add(i, -1);
	
	cout << endl;
	cout << count(5) - count(4) << endl;
		
	
	return 0;
}